package com.lishe.lishe.lishe.module.me.fragments;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lishe.lishe.R;
import com.lishe.lishe.asynchttp.LSWebHelper;
import com.lishe.lishe.lishe.module.me.http.HttpUserCenter;

import org.json.JSONObject;

/**
 * Created by zhcasecom on 2017/8/17.
 * 礼舍币
 */

public class FragmentCash extends Fragment {
    private TextView myCoins;
    private String TAG = getClass().getSimpleName();
    private static String cash_amount;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_my_cash, container, false);
        myCoins = view.findViewById(R.id.lishe_money);
        return view;
    }
    public static FragmentCash newInstance(){
        FragmentCash instance = new FragmentCash();
        Bundle bundle = new Bundle();
        instance.setArguments(bundle);
        return instance;
    }

    private void getLishebiData() {
        try {
            HttpUserCenter.getLisheMoney(null, response);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    LSWebHelper.WebCallBack response = new LSWebHelper.WebCallBack() {
        @Override
        public void onSuccess(JSONObject dataJson, String dataString, String message) {
            JSONObject data = dataJson;
            cash_amount = data.optString("lisheMoney");
            setText(cash_amount);
        }

        @Override
        public void onFailure(String message) {

        }
    };
    public void setText(String data) {
        myCoins.setText(data);
    }

    @Override
    public void onResume() {
        super.onResume();
        getLishebiData();
    }
}
